<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('主订单列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>订单编号：</label>
                            <input type="text" name="orderId"/>
                        </li>
                        <li>
                            <label>品名：</label>
                            <input type="text" name="productName"/>
                        </li>
                        <li>
                            <label>客户名称：</label>
                            <input type="text" name="customerName"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="cardbox:orders:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="cardbox:orders:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="cardbox:orders:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="cardbox:orders:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('cardbox:orders:edit')}]];
    var removeFlag = [[${@permission.hasPermi('cardbox:orders:remove')}]];
    var prefix = ctx + "cardbox/orders";

    // 新增更新状态按钮对应的JS函数
    function updateOrderStatus(id) {
        $.ajax({
            url: prefix + '/editStatus/' + id,
            type: 'PUT',
            success: function(res) {
                if (res.code === 0) {
                    $.modal.msgSuccess("状态更新成功");
                    // 刷新表格
                    $.table.refresh();
                } else {
                    $.modal.msgError("更新失败：" + res.msg);
                }
            },
            error: function() {
                $.modal.msgError("请求异常");
            }
        });
    }

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "主订单",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'orderId',
                    title: '订单编号'
                },
                {
                    field: 'productName',
                    title: '品名'
                },
                {
                    field: 'customerName',
                    title: '客户名称'
                },
                {
                    field: 'boxQuantity',
                    title: '纸箱订单量（套）'
                },
                {
                    field: 'outBoxQuantity',
                    title: '纸箱出库数量（套）'
                },
                {
                    field: 'processingFee',
                    title: '加工费'
                },
                {
                    field: 'boxArea',
                    title: '整批纸箱面积（m²）'
                },
                {
                    field: 'cardboardQuantity',
                    title: '纸板订单量（张）'
                },
                {
                    field: 'inCardboardQuantity',
                    title: '纸板入库数量（张）'
                },
                {
                    field: 'cardboardArea',
                    title: '整批纸板面积（m²）'
                },
                {
                    field: 'remainingArea',
                    title: '剩余面积（m²）'
                },
                {
                    field: 'cardboardPrice',
                    title: '整批外购纸板价格'
                },
                {
                    field: 'profit',
                    title: '纸箱单个利润（元/套）'
                },
                {
                    field: 'tax',
                    title: '税率/%'
                },
                {
                    field: 'batchProfit',
                    title: '整批利润'
                },
                {
                    field: 'status',
                    title: '订单状态'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="updateOrderStatus(\'' + row.id + '\')"><i class="fa fa-refresh"></i>更新状态</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>
